package com.maxd.modules.selfshop.merchants.controller;

import com.maxd.adapter.IgnoreSecurity;
import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.modules.selfshop.merchants.entity.SelfStore;
import com.maxd.modules.selfshop.merchants.respository.SelfStoreJpaRepository;
import com.maxd.modules.selfshop.merchants.service.SelfStoreService;
import com.maxd.respository.selfActivity.SelfActivityRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value="自营商城店铺管理",tags={"自营商城店铺管理"})
@RequestMapping(value = "/self/store")
public class SelfStoreController {
    @Autowired
    private SelfStoreService service;
    @Autowired
    private SelfStoreJpaRepository selfStoreJpaRepository;


    @IgnoreSecurity
    @GetMapping("/list")
    @ApiOperation("店铺列表")
    public Result findAll(Integer page, Integer size,
                          @ApiParam("店铺名称") @RequestParam(required = false) String storeName) {
        return service.findAll(page, size, storeName);
    }

    @IgnoreSecurity
    @GetMapping("/find")
    @ApiOperation("查询")
    public Result findOne(Long id) {
        return service.findOne(id);
    }

    @IgnoreSecurity
    @PostMapping("/save")
    @ApiOperation("添加")
    public Result saveBody(@RequestBody SelfStore entity) {
        return service.saveBody(entity);
    }

    @IgnoreSecurity
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result updateBody(@RequestBody SelfStore entity) {
        return service.updateBody(entity);
    }

    @GetMapping("/delete")
    @ApiOperation("删除")
    public Result delete(Long id) {
        return service.delete(id);
    }

    @IgnoreSecurity
    @GetMapping("/findByMerchant")
    @ApiOperation("商户的店铺")
    public Result findByMerchant(Long merchantId) {
        return service.findByMerchant(merchantId);
    }

    @GetMapping("/ban")
    @ApiOperation("总后台封禁解封店铺")
    public Result ban(@ApiParam("店铺id")Long storeId, @ApiParam("状态 1解封 2封禁")Integer banStatus) {
        return service.ban(storeId, banStatus);
    }

    @IgnoreSecurity
    @GetMapping("/count")
    @ApiOperation("店铺数据中心")
    public Result count(Long storeId,String data) {
        return service.count(storeId,data);
    }

    @PostMapping("/updateStoreBankCard")
    @ApiOperation("修改银行卡信息")
    public Result updateStoreBankCard(Long storeId,String bankCard,String bankCardName,String bankCarUserName){
        SelfStore selfStore = selfStoreJpaRepository.findById(storeId).orElse(null);
        selfStore.setBankCard(bankCard);
        selfStore.setBankCardName(bankCardName);
        selfStore.setBankCarUserName(bankCarUserName);
        selfStoreJpaRepository.save(selfStore);
        return ResultUtil.success();
    }

    @PostMapping("/updateMsgContent")
    @ApiOperation("修改自动回复")
    public Result updateMsgContent(Long storeId,String msgContent){
        SelfStore selfStore = selfStoreJpaRepository.findById(storeId).orElse(null);
        selfStore.setMsgContent(msgContent);
        selfStoreJpaRepository.save(selfStore);
        return ResultUtil.success();
    }

}
